package org.springside.examples.miniweb.web.user;

import org.springframework.beans.factory.annotation.Required;
import org.springside.examples.miniweb.entity.user.User;
import org.springside.examples.miniweb.service.user.UserManager;
import org.springside.modules.web.struts2.CRUDAction;

/**
 * 用户管理Action. 本Action演示完整的Struts2 Action写法.继承于CRUDAction的更简单版本见{RoleAction}.
 * 
 * @author calvin
 */    
@SuppressWarnings( { "serial", "unchecked" })
public class AuthAction extends CRUDAction<User> {
	private UserManager userManager;
	private Integer id;
 
	public String login() throws Exception {
		
		if (userManager.auth(this.entity.getLoginName(), this.entity
				.getPassword())) {
			return SUCCESS;
		} else {
			this.msg = "用户名或密码不正确，请重新输入！";
			return ERROR;

		}
	}

	@Override
	public String execute() throws Exception {
		return login();
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Override
	protected Integer getId() {
		return id;
	}

	@Required
	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}

	@Override
	protected Object getManager() {
		return userManager;
	}

}
